using UnityEngine;
using UnityEngine.UIElements;

public class Rotationj360 : MonoBehaviour
{
    public Inspector inspector;
    private VisualElement imgElement;
    private bool isDragging;
    private Vector3 startMousePosition;
    void Start()
    {
        imgElement = (inspector.typeDic["Res"] as ResInspector).typeDic["model"].Q<VisualElement>("content");
        imgElement.RegisterCallback<PointerDownEvent>(OnPointerDown);
        imgElement.RegisterCallback<PointerUpEvent>(OnPointerUp);
        imgElement.RegisterCallback<PointerMoveEvent>(OnPointerMove);
    }

    private void OnPointerDown(PointerDownEvent evt)
    {
        isDragging = true;
        startMousePosition = evt.position; // 记录初始鼠标位置
        imgElement.CapturePointer(evt.pointerId); // 捕获指针
    }

    private void OnPointerUp(PointerUpEvent evt)
    {
        isDragging = false;
        imgElement.ReleasePointer(evt.pointerId); // 释放指针
    }

    private void OnPointerMove(PointerMoveEvent evt)
    {
        if (!isDragging) return;
         var delta = evt.position - startMousePosition;
        CameraAutoFitter.Instance.Drag(evt.deltaPosition.normalized);
    }
}
